<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Modclient extends CI_Model 
{

    function __construct()
    {
        parent::__construct();
    	$this->load->database();

	}
	
//################## commun function################################
	public function updatetemplate($tablename,$data,$where)
		{
				
			$str = $this->db->update_string($tablename, $data, $where);
			
			$query = $this->db->query($str);
			//print_r($query);
			
		}	
		
	public function insertetemplate($tablename,$data)
		{
				
			$str = $this->db->insert_string($tablename, $data);
			 
			$query = $this->db->query($str);
			$idinsert=$this->db->insert_id();
			return $idinsert;
			
		}	

		
		
//######################### end commun function###########################

	public function getlistproducts()
	{
		$query=$this->db->query("select * from products");
		return $query->result_array();
	}	
	

	public  function getlistproductbypage($per_page,$startrows)
	{
		$query = $this->db->select("*")->get('products',$per_page,$startrows);
		return $query->result_array();
	}
	
	public function findproductbyid($idproducts)
	{
		$query=$this->db->select("*")->get_where("products",array("idproducts"=>$idproducts));
		return $query->result_array();
		
	}
	
	public  function getlistproductbycats($cats,$per_page,$startrows)
	{
		$query = $this->db->select("*")->get_where('products',array('Catalog' => $cats),$per_page,$startrows);
		return $query->result_array();
	}
	
	public  function getlistproductbypaysfiltre($cats,$pays,$per_page,$startrows)
	{
		if($cats=="all")
		{	
			$this->db->like('LOWER(Comment)', strtolower($pays));
			$query = $this->db->select("*")->get('products',$per_page,$startrows);
			
		}else 
		{		
		$this->db->like('LOWER(Comment)', strtolower($pays));
		$query =$this->db->select("*")->get_where('products',array('Catalog' => $cats),$per_page,$startrows);
		
		}	
		return $query->result_array();
	}
	
	public function recherche($key,$per_page,$startrows)
	{
		$this->db->like('LOWER(description)', strtolower($key));
		$this->db->or_like('LOWER(Comment)', strtolower($key));
		$this->db->or_like('LOWER(ItemCode)', strtolower($key));
		$this->db->limit($per_page, $startrows);
		$query=$this->db->get("products");
		return $query->result_array(); 
		
	}
	
}
